package main

import (
	"context"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rpcinterface/client/market"
	"github.com/robfig/cron"
)

func main() {
	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	c := cron.New()
	//每天0点执行一次---用于更新体验状态
	_ = c.AddFunc("0 0 0 * * ?", autoUpdateExperience)
	//_ = c.AddFunc("@every 10s", AutoUpdateExperience)
	c.Start()
	select {}
}

// 定时自动更新拼团活动状态：未开始->进行中；进行中->已结束
func autoUpdateExperience() {
	rpcExperience := new(market.Experience).Init()
	defer rpcExperience.Close()
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("crontab.log.autoUpdateExperienceStatus"))

	var reply bool
	var args bool
	if err := rpcExperience.AutoUpdateStatus(context.Background(), &args, &reply); err != nil {
		utils.Logerr.Printf("定时自动更新一元体验活动状态失败，错误：%s\n", err.Error())
		return
	}
	//utils.Logerr.Printf("定时自动更新一元体验活动状态完成")
}
